<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAdminUsersTable extends Migration
{
    /**
     * Run the migrations.
     * 后台权限相关表
     * @return void
     */
    public function up()
    {
        Schema::create('admin_users', function (Blueprint $table) {
            $table->unsignedBigInteger('admin_uid')->comment('管理员ID')->primary();
            $table->string('account', 255)->comment('帐号');
            $table->string('password', 100)->comment('密码');
            $table->string('name', 255)->comment('管理员名称');
            $table->string('avatar', 255)->nullable()->comment('管理员头像');
            $table->boolean('sex')->default(0)->comment('性别 0: 无 1: 男 2: 女');
            $table->tinyInteger('source_type')->comment('来源类型 0: 系统 1: 后台');

            $table->timestamps();
            $table->softDeletes();

            $table->engine = 'InnoDB';
        });
        Schema::create('admin_roles', function (Blueprint $table) {
            $table->unsignedBigInteger('role_uid')->comment('角色ID')->primary();
            $table->string('name', 200)->comment('角色名称');
            $table->string('code', 200)->comment('角色标识');
            $table->string('description', 200)->comment('描述');

            $table->timestamps();
            $table->softDeletes();

            $table->engine = 'InnoDB';
        });
        Schema::create('admin_role_user', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('自增ID');
            $table->unsignedBigInteger('admin_uid')->comment('管理员ID')->index();
            $table->unsignedBigInteger('role_uid')->comment('角色ID')->index();

            $table->timestamps();
            $table->softDeletes();

            $table->engine = 'InnoDB';
        });
        Schema::create('admin_menus', function (Blueprint $table) {
            $table->unsignedBigInteger('menu_uid')->comment('菜单ID')->primary();
            $table->unsignedBigInteger('parent_uid')->comment('父菜单ID')->index();
            $table->string('title', 200)->comment('标题');
            $table->string('path', 255)->comment('路径');
            $table->string('icon', 100)->nullable()->comment('图标');
            $table->string('permission', 200)->nullable()->comment('权限标识');
            $table->unsignedTinyInteger('sort')->comment('排序');
            $table->tinyInteger('type')->comment('类型 1: 菜单 2: 功能');

            $table->timestamps();
            $table->softDeletes();

            $table->engine = 'InnoDB';
        });
        Schema::create('admin_menu_role', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('自增ID');
            $table->unsignedBigInteger('menu_uid')->comment('菜单ID')->index();
            $table->unsignedBigInteger('role_uid')->comment('角色ID')->index();

            $table->timestamps();
            $table->softDeletes();

            $table->engine = 'InnoDB';
        });

       

        DB::statement("alter table `admin_users` comment'后台管理员表'");
        DB::statement("alter table `admin_roles` comment'后台角色表'");
        DB::statement("alter table `admin_role_user` comment'后台角色用户表'");
        DB::statement("alter table `admin_menus` comment'后台菜单表'");
        DB::statement("alter table `admin_menu_role` comment'后台菜单角色表'");

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin_users');
        Schema::dropIfExists('admin_roles');
        Schema::dropIfExists('admin_role_user');
    }
};
